package com.xmtlxx.web.controller.tms.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import com.xmtlxx.common.annotation.Log;
import com.xmtlxx.common.annotation.RepeatSubmit;
import com.xmtlxx.common.core.controller.BaseController;
import com.xmtlxx.common.core.domain.PageQuery;
import com.xmtlxx.common.core.domain.R;
import com.xmtlxx.common.core.domain.entity.SysUser;
import com.xmtlxx.common.core.page.TableDataInfo;
import com.xmtlxx.common.core.validate.AddGroup;
import com.xmtlxx.common.core.validate.EditGroup;
import com.xmtlxx.common.core.validate.QueryGroup;
import com.xmtlxx.common.enums.BusinessType;
import com.xmtlxx.common.helper.LoginHelper;
import com.xmtlxx.common.utils.StringUtils;
import com.xmtlxx.common.utils.poi.ExcelUtil;
import com.xmtlxx.oms.domain.Task;
import com.xmtlxx.oms.domain.TaskDtl;
import com.xmtlxx.oms.domain.bo.TaskBo;
import com.xmtlxx.oms.domain.bo.TaskDtlBo;
import com.xmtlxx.oms.domain.vo.StagingVo;
import com.xmtlxx.oms.domain.vo.TaskDtlVo;
import com.xmtlxx.oms.domain.vo.TaskVo;
import com.xmtlxx.oms.service.ITaskDtlService;
import com.xmtlxx.system.domain.SysOss;
import com.xmtlxx.system.domain.bo.SysOssBo;
import com.xmtlxx.system.service.ISysOssService;
import com.xmtlxx.system.service.ISysUserService;
import com.xmtlxx.tms.domain.bo.*;
import com.xmtlxx.tms.domain.vo.*;
import com.xmtlxx.tms.service.ICarService;
import com.xmtlxx.tms.service.ICarrierService;
import com.xmtlxx.web.controller.oms.service.IStagingService;
import com.xmtlxx.web.controller.oms.service.ITaskService;
import com.xmtlxx.web.controller.tms.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 订单Controller
 *
 * @author xmtlxx
 * @date 2022-08-15
 */
@Validated
@Api(value = "订单控制器", tags = {"订单管理"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/tms/order")
public class OrderController extends BaseController {

    private final IOrderService iOrderService;

    private final IOrderDtlService iOrderDtlService;

    private final IWaybillService iWaybillService;

    private final IWaybillDtlService iWaybillDtlService;

    private final IWaybillLogService iWaybillLogService;

    private final ISysOssService iSysOssService;

    private final ICarrierService iCarrierService;

    private final IStagingService stagingService;

    private final ISysUserService userService;

    private final ICarService carService;

    private final ITaskService taskService;

    private final ITaskDtlService taskDtlService;

    /**
     * 返回一个初始化的对象到前端，方便进行动态渲染
     */
    @ApiOperation("用于返回一个初始化对象")
    @PostMapping("/initBean")
    R<OrderVo> initBean() {

        OrderVo vo = new OrderVo();
        //可以对数据进行初始化
        return R.ok(vo);
    }

    /**
     * 查询订单列表
     */
    @ApiOperation("查询订单列表")
//    @SaCheckPermission("tms:order:list")
    @GetMapping("/list")
    public TableDataInfo<OrderVo> list(@Validated(QueryGroup.class) OrderBo bo, PageQuery pageQuery) {

        if (LoginHelper.getLoginUser().getRolePermission().contains("smscys")) {
            bo.setCarrierDeptId(LoginHelper.getDeptId());
        } else if (LoginHelper.getLoginUser().getRolePermission().contains("qujianyuan") || LoginHelper.getLoginUser().getRolePermission().contains("paijianyuan")) {
            bo.setPickupId(LoginHelper.getUserId());
        } else {
            bo.setStoreDept(LoginHelper.getDeptId());
        }
        return iOrderService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出订单列表
     */
    @ApiOperation("导出订单列表")
    @SaCheckPermission("tms:order:export")
    @Log(title = "订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(@Validated OrderBo bo, HttpServletResponse response) {

        List<OrderVo> list = iOrderService.queryList(bo);
        ExcelUtil.exportExcel(list, "订单", OrderVo.class, response);
    }

    /**
     * 获取订单详细信息
     */
    @ApiOperation("获取订单详细信息")
//    @SaCheckPermission("tms:order:query")
    @GetMapping("/{id}")
    public R<OrderVo> getInfo(@ApiParam("主键")
                              @NotNull(message = "主键不能为空")
                              @PathVariable("id") String id) {

        OrderVo vo = iOrderService.queryById(id);
        TaskVo taskVo = taskService.queryById(vo.getTaskId());
        vo.setDelivery(taskVo.getDelivery());
        vo.setStoreDeptName(taskVo.getStoreDeptName());
        OrderDtlBo orderDtlBo = new OrderDtlBo();
        orderDtlBo.setOrderId(vo.getId());
        List<OrderDtlVo> dtlVos = iOrderDtlService.queryList(orderDtlBo);
        dtlVos.stream().forEach(item -> {

            List<StagingVo> stagingVoList = stagingService.getStaingByNo(item.getPno());

            List<StagingVo> stagingVos = stagingVoList.stream().map(result -> {
                StagingVo stagingVo = stagingService.queryById(result.getId());

                SysOssBo oss = new SysOssBo();
                oss.setObjid(result.getId());
                oss.setBuss("staging");
                stagingVo.setOss(iSysOssService.selectSysOssList(oss));

                return stagingVo;
            }).collect(Collectors.toList());

            item.setStagingVos(stagingVos);

            item.setIsDtlShow(false);
        });
        vo.setItems(dtlVos);

        WaybillBo waybillBo = new WaybillBo();
        waybillBo.setOrderId(vo.getId());

        List<WaybillVo> items = iWaybillService.queryList(waybillBo);
        if (items != null && items.size() > 0) {
            for (WaybillVo waybillVo : items) {
                WaybillDtlBo waybillDtlBo = new WaybillDtlBo();
                waybillDtlBo.setWaybillId(waybillVo.getId());
                waybillVo.setItems(iWaybillDtlService.queryList(waybillDtlBo));
                if (vo.getPickupId() != null) {
                    waybillVo.setDriverTel(userService.selectUserById(vo.getPickupId()).getPhonenumber());
                }

                WaybillLogBo waybillLogBo = new WaybillLogBo();
                waybillLogBo.setTrackId(waybillVo.getId());
                waybillVo.setLogItems(iWaybillLogService.queryList(waybillLogBo));
                vo.setScheduleId(waybillVo.getScheduleId());
                vo.setScheduleDayName(waybillVo.getScheduleDayName());
            }
        }
        vo.setWayItems(items);
        if (items != null && items.size() > 0) {
            vo.setScheduleId(items.get(0).getScheduleId());
        }

        if (!StringUtils.isEmpty(vo.getSourceType()) && vo.getSourceType().equals("1")) {
            OrderBo bo = new OrderBo();
            bo.setFid(vo.getFid());
            vo.setOrderItems(iOrderService.queryList(bo));
        }

        //全车外观正前
        SysOssBo facadeOss = new SysOssBo();
        facadeOss.setObjid(vo.getId());
        facadeOss.setBuss("facade");
        List<SysOss> facadeOssList = iSysOssService.selectSysOssList(facadeOss);
        if (facadeOssList == null || facadeOssList.size() == 0) {
            facadeOssList = new ArrayList<>();
        }
        vo.setFacadeOss(facadeOssList);

        //全车外观正左
        SysOssBo facadeLeftOss = new SysOssBo();
        facadeLeftOss.setObjid(vo.getId());
        facadeLeftOss.setBuss("facadeLeft");
        List<SysOss> facadeLeftOssList = iSysOssService.selectSysOssList(facadeLeftOss);
        if (facadeLeftOssList == null || facadeLeftOssList.size() == 0) {
            facadeLeftOssList = new ArrayList<>();
        }
        vo.setFacadeLeftOss(facadeLeftOssList);

        //全车外观正后
        SysOssBo facadeAfterOss = new SysOssBo();
        facadeAfterOss.setObjid(vo.getId());
        facadeAfterOss.setBuss("facadeAfter");
        List<SysOss> facadeAfterOssList = iSysOssService.selectSysOssList(facadeAfterOss);
        if (facadeAfterOssList == null || facadeAfterOssList.size() == 0) {
            facadeAfterOssList = new ArrayList<>();
        }
        vo.setFacadeAfterOss(facadeAfterOssList);

        //全车外观正右
        SysOssBo facadeRightOss = new SysOssBo();
        facadeRightOss.setObjid(vo.getId());
        facadeRightOss.setBuss("facadeRight");
        List<SysOss> facadeRightOssList = iSysOssService.selectSysOssList(facadeRightOss);
        if (facadeRightOssList == null || facadeRightOssList.size() == 0) {
            facadeRightOssList = new ArrayList<>();
        }
        vo.setFacadeRightOss(facadeRightOssList);

        //仪表盘
        SysOssBo dashboardOss = new SysOssBo();
        dashboardOss.setObjid(vo.getId());
        dashboardOss.setBuss("dashboard");
        List<SysOss> dashboardOssList = iSysOssService.selectSysOssList(dashboardOss);
        if (dashboardOssList == null || dashboardOssList.size() == 0) {
            dashboardOssList = new ArrayList<>();
        }
        vo.setDashboardOss(dashboardOssList);

        //车架号
        SysOssBo carOss = new SysOssBo();
        carOss.setObjid(vo.getId());
        carOss.setBuss("carNumber");
        List<SysOss> carOssList = iSysOssService.selectSysOssList(carOss);
        if (carOssList == null || carOssList.size() == 0) {
            carOssList = new ArrayList<>();
        }
        vo.setCarOss(carOssList);

        //车钥匙
        SysOssBo carKeyOss = new SysOssBo();
        carKeyOss.setObjid(vo.getId());
        carKeyOss.setBuss("carKey");
        List<SysOss> carKeyOssList = iSysOssService.selectSysOssList(carKeyOss);
        if (carKeyOssList == null || carKeyOssList.size() == 0) {
            carKeyOssList = new ArrayList<>();
        }
        vo.setCarKeyOss(carKeyOssList);
        //行驶证
        SysOssBo driveLicenOss = new SysOssBo();
        driveLicenOss.setObjid(vo.getId());
        driveLicenOss.setBuss("driveLicen");
        List<SysOss> driveLicenOssList = iSysOssService.selectSysOssList(driveLicenOss);
        if (driveLicenOssList == null || driveLicenOssList.size() == 0) {
            driveLicenOssList = new ArrayList<>();
        }
        vo.setDriveLicenOss(driveLicenOssList);
        //登记书
        SysOssBo registerBookOss = new SysOssBo();
        registerBookOss.setObjid(vo.getId());
        registerBookOss.setBuss("registerBook");
        List<SysOss> registerBookOssList = iSysOssService.selectSysOssList(registerBookOss);
        if (registerBookOssList == null || registerBookOssList.size() == 0) {
            registerBookOssList = new ArrayList<>();
        }
        vo.setRegisterBookOss(registerBookOssList);

        //交接现场
        SysOssBo handoverOss = new SysOssBo();
        handoverOss.setObjid(vo.getId());
        handoverOss.setBuss("handover");
        List<SysOss> handoverOssList = iSysOssService.selectSysOssList(handoverOss);
        if (handoverOssList == null || handoverOssList.size() == 0) {
            handoverOssList = new ArrayList<>();
        }
        vo.setHandoverOss(handoverOssList);


        //装车
        SysOssBo loadOss = new SysOssBo();
        loadOss.setObjid(vo.getId());
        loadOss.setBuss("load");
        List<SysOss> loadOssList = iSysOssService.selectSysOssList(loadOss);
        if (loadOssList == null || loadOssList.size() == 0) {
            loadOssList = new ArrayList<>();
        }
        vo.setLoadOss(loadOssList);

        //瑕疵
        SysOssBo flawOss = new SysOssBo();
        flawOss.setObjid(vo.getId());
        flawOss.setBuss("flaw");
        List<SysOss> flawOssList = iSysOssService.selectSysOssList(flawOss);
        if (flawOssList == null || flawOssList.size() == 0) {
            flawOssList = new ArrayList<>();
        }
        vo.setFlawOss(flawOssList);


        //目的地
        SysOssBo takeOss = new SysOssBo();
        takeOss.setObjid(vo.getId());
        takeOss.setBuss("take");
        List<SysOss> takeOssList = iSysOssService.selectSysOssList(takeOss);
        if (takeOssList == null || takeOssList.size() == 0) {
            takeOssList = new ArrayList<>();
        }
        vo.setTakeOss(takeOssList);


        //卸车
        SysOssBo unloadOss = new SysOssBo();
        unloadOss.setObjid(vo.getId());
        unloadOss.setBuss("unload");
        List<SysOss> unloadOssList = iSysOssService.selectSysOssList(unloadOss);
        if (unloadOssList == null || unloadOssList.size() == 0) {
            unloadOssList = new ArrayList<>();
        }
        vo.setUnloadOss(unloadOssList);


        //取件其他
        SysOssBo otherOss = new SysOssBo();
        otherOss.setObjid(vo.getId());
        otherOss.setBuss("other");
        List<SysOss> otherOssList = iSysOssService.selectSysOssList(otherOss);
        if (otherOssList == null || otherOssList.size() == 0) {
            otherOssList = new ArrayList<>();
        }
        vo.setOtherOss(otherOssList);

        //到达其他
        SysOssBo otherTwoOss = new SysOssBo();
        otherTwoOss.setObjid(vo.getId());
        otherTwoOss.setBuss("otherTwo");
        List<SysOss> otherTwoOssList = iSysOssService.selectSysOssList(otherTwoOss);
        if (otherTwoOssList == null || otherTwoOssList.size() == 0) {
            otherTwoOssList = new ArrayList<>();
        }
        vo.setOtherTwoOss(otherTwoOssList);

        return R.ok(vo);
    }

    /**
     * 获取订单详细信息
     */
    @ApiOperation("获取订单详细信息")
//    @SaCheckPermission("tms:order:query")
    @GetMapping("getTaskInfo/{id}")
    public R<OrderVo> getTaskInfo(@ApiParam("主键")
                                  @NotNull(message = "主键不能为空")
                                  @PathVariable("id") String id) {
        String taskId =  id;
        TaskVo task = taskService.getTaskById(id);

        if (StrUtil.isNotBlank(task.getReplaceNo())) {
            TaskBo taskBo = new TaskBo();
            taskBo.setTaskNo(task.getReplaceNo());
            TaskVo taskVo = taskService.selectTaskVoByTaskNo(taskBo);
            taskId = taskVo.getId();
        }

        OrderVo vo = iOrderService.queryByTaskId(taskId);
        if (vo != null) {
            OrderDtlBo orderDtlBo = new OrderDtlBo();
            orderDtlBo.setOrderId(vo.getId());

            List<OrderDtlVo> orderDtlVos = iOrderDtlService.queryList(orderDtlBo);
            //单子替换只显示下单财物
            if (StrUtil.isNotBlank(task.getReplaceNo())) {

                TaskDtlBo taskDtlBo = new TaskDtlBo();
                taskDtlBo.setTaskId(taskId);
                taskDtlBo.setDelFlag("0");
                List<TaskDtlVo> taskDtls = taskDtlService.queryList(taskDtlBo);
                List<String> taskDtlPNos = taskDtls.stream().map(TaskDtlVo::getPno).collect(Collectors.toList());

                orderDtlVos = orderDtlVos.stream().filter(item -> taskDtlPNos.contains(item.getPno())).collect(Collectors.toList());
            }

            vo.setItems(orderDtlVos);

            if (vo.getPickupId() != null) {
                SysUser user = userService.selectUserById(vo.getPickupId());
                vo.setPickupTel(user.getPhonenumber());
            }
            if (vo.getBuss().equals("0")) {
                if (StringUtils.isNotEmpty(vo.getCarId())) {
                    CarVo carVo = carService.queryById(vo.getCarId());
                    vo.setCarNumber(carVo.getCarNumber());
                }
            }

            WaybillBo waybillBo = new WaybillBo();
            waybillBo.setOrderId(vo.getId());
            List<WaybillVo> items = iWaybillService.queryList(waybillBo);
            if (items != null && items.size() > 0) {
                for (WaybillVo waybillVo : items) {
                    WaybillDtlBo waybillDtlBo = new WaybillDtlBo();
                    waybillDtlBo.setWaybillId(waybillVo.getId());
                    waybillVo.setItems(iWaybillDtlService.queryList(waybillDtlBo));
                    if (StringUtils.isEmpty(waybillVo.getCarNumber())) {
                        waybillVo.setCarNumber(vo.getCarNumber());
                    }

                    WaybillLogBo waybillLogBo = new WaybillLogBo();
                    waybillLogBo.setTrackId(waybillVo.getId());
                    waybillVo.setLogItems(iWaybillLogService.queryList(waybillLogBo));
                }
            }
            vo.setWayItems(items);

            //承运商
            if (vo.getCarrierDeptId() != null) {
                CarrierBo carrierBo = new CarrierBo();
                carrierBo.setDeptId(vo.getCarrierDeptId());
                List<CarrierVo> carrierVos = iCarrierService.queryList(carrierBo);
                if (carrierVos != null && carrierVos.size() > 0) {
                    vo.setCarrierName(carrierVos.get(0).getNickName());
                }
            }


            //全车外观正前
            SysOssBo facadeOss = new SysOssBo();
            facadeOss.setObjid(vo.getId());
            facadeOss.setBuss("facade");
            List<SysOss> facadeOssList = iSysOssService.selectSysOssList(facadeOss);
            if (facadeOssList == null || facadeOssList.size() == 0) {
                facadeOssList = new ArrayList<>();
            }
            vo.setFacadeOss(facadeOssList);

            //全车外观正左
            SysOssBo facadeLeftOss = new SysOssBo();
            facadeLeftOss.setObjid(vo.getId());
            facadeLeftOss.setBuss("facadeLeft");
            List<SysOss> facadeLeftOssList = iSysOssService.selectSysOssList(facadeLeftOss);
            if (facadeLeftOssList == null || facadeLeftOssList.size() == 0) {
                facadeLeftOssList = new ArrayList<>();
            }
            vo.setFacadeLeftOss(facadeLeftOssList);

            //全车外观正后
            SysOssBo facadeAfterOss = new SysOssBo();
            facadeAfterOss.setObjid(vo.getId());
            facadeAfterOss.setBuss("facadeAfter");
            List<SysOss> facadeAfterOssList = iSysOssService.selectSysOssList(facadeAfterOss);
            if (facadeAfterOssList == null || facadeAfterOssList.size() == 0) {
                facadeAfterOssList = new ArrayList<>();
            }
            vo.setFacadeAfterOss(facadeAfterOssList);

            //全车外观正右
            SysOssBo facadeRightOss = new SysOssBo();
            facadeRightOss.setObjid(vo.getId());
            facadeRightOss.setBuss("facadeRight");
            List<SysOss> facadeRightOssList = iSysOssService.selectSysOssList(facadeRightOss);
            if (facadeRightOssList == null || facadeRightOssList.size() == 0) {
                facadeRightOssList = new ArrayList<>();
            }
            vo.setFacadeRightOss(facadeRightOssList);

            //仪表盘
            SysOssBo dashboardOss = new SysOssBo();
            dashboardOss.setObjid(vo.getId());
            dashboardOss.setBuss("dashboard");
            List<SysOss> dashboardOssList = iSysOssService.selectSysOssList(dashboardOss);
            if (dashboardOssList == null || dashboardOssList.size() == 0) {
                dashboardOssList = new ArrayList<>();
            }
            vo.setDashboardOss(dashboardOssList);

            //车架号
            SysOssBo carOss = new SysOssBo();
            carOss.setObjid(vo.getId());
            carOss.setBuss("carNumber");
            List<SysOss> carOssList = iSysOssService.selectSysOssList(carOss);
            if (carOssList == null || carOssList.size() == 0) {
                carOssList = new ArrayList<>();
            }
            vo.setCarOss(carOssList);

            //交接现场
            SysOssBo handoverOss = new SysOssBo();
            handoverOss.setObjid(vo.getId());
            handoverOss.setBuss("handover");
            List<SysOss> handoverOssList = iSysOssService.selectSysOssList(handoverOss);
            if (handoverOssList == null || handoverOssList.size() == 0) {
                handoverOssList = new ArrayList<>();
            }
            vo.setHandoverOss(handoverOssList);


            //装车
            SysOssBo loadOss = new SysOssBo();
            loadOss.setObjid(vo.getId());
            loadOss.setBuss("load");
            List<SysOss> loadOssList = iSysOssService.selectSysOssList(loadOss);
            if (loadOssList == null || loadOssList.size() == 0) {
                loadOssList = new ArrayList<>();
            }
            vo.setLoadOss(loadOssList);

            //瑕疵
            SysOssBo flawOss = new SysOssBo();
            flawOss.setObjid(vo.getId());
            flawOss.setBuss("flaw");
            List<SysOss> flawOssList = iSysOssService.selectSysOssList(flawOss);
            if (flawOssList == null || flawOssList.size() == 0) {
                flawOssList = new ArrayList<>();
            }
            vo.setFlawOss(flawOssList);


            //目的地
            SysOssBo takeOss = new SysOssBo();
            takeOss.setObjid(vo.getId());
            takeOss.setBuss("take");
            List<SysOss> takeOssList = iSysOssService.selectSysOssList(takeOss);
            if (takeOssList == null || takeOssList.size() == 0) {
                takeOssList = new ArrayList<>();
            }
            vo.setTakeOss(takeOssList);


            //卸车
            SysOssBo unloadOss = new SysOssBo();
            unloadOss.setObjid(vo.getId());
            unloadOss.setBuss("unload");
            List<SysOss> unloadOssList = iSysOssService.selectSysOssList(unloadOss);
            if (unloadOssList == null || unloadOssList.size() == 0) {
                unloadOssList = new ArrayList<>();
            }
            vo.setUnloadOss(unloadOssList);


            //其他图片
            SysOssBo otherOss = new SysOssBo();
            otherOss.setObjid(vo.getId());
            otherOss.setBuss("other");
            List<SysOss> otherOssList = iSysOssService.selectSysOssList(otherOss);
            if (otherOssList == null || otherOssList.size() == 0) {
                otherOssList = new ArrayList<>();
            }
            vo.setOtherOss(otherOssList);

            //到达其他
            SysOssBo otherTwoOss = new SysOssBo();
            otherTwoOss.setObjid(vo.getId());
            otherTwoOss.setBuss("otherTwo");
            List<SysOss> otherTwoOssList = iSysOssService.selectSysOssList(otherTwoOss);
            if (otherTwoOssList == null || otherTwoOssList.size() == 0) {
                otherTwoOssList = new ArrayList<>();
            }
            vo.setOtherTwoOss(otherTwoOssList);


        }
        return R.ok(vo);
    }

    /**
     * 新增订单
     */
    @ApiOperation("新增订单")
//    @SaCheckPermission("tms:order:add")
    @Log(title = "订单", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    @Transactional(rollbackFor = Exception.class)
    public R<OrderVo> add(@Validated(AddGroup.class) @RequestBody OrderVo vo) {

        OrderBo bo = new OrderBo();
        BeanUtil.copyProperties(vo, bo);
        return R.ok(iOrderService.insertByBo(bo));
    }

    /**
     * 修改订单
     */
    @ApiOperation("修改订单")
//    @SaCheckPermission("tms:order:edit")
    @Log(title = "订单", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    @Transactional(rollbackFor = Exception.class)
    public R<OrderVo> edit(@Validated(EditGroup.class) @RequestBody OrderVo vo) {

        OrderBo bo = new OrderBo();
        BeanUtil.copyProperties(vo, bo);
        return R.ok(iOrderService.updateByBo(bo));
    }

    /**
     * 删除订单
     */
    @ApiOperation("删除订单")
    @SaCheckPermission("tms:order:remove")
    @Log(title = "订单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @Transactional(rollbackFor = Exception.class)
    public R<Void> remove(@ApiParam("主键串")
                          @NotEmpty(message = "主键不能为空")
                          @PathVariable String[] ids) {

        return toAjax(iOrderService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }

    /**
     * 页面展示，根据订单id展示财物列表
     */
    @PostMapping("/getOrderDtls/{ids}")
    public R<Map<String, Object>> getOrderIdByDtls(@ApiParam("主键串")
                                                   @NotEmpty(message = "主键不能为空")
                                                   @PathVariable String[] ids) {

        return R.ok(iOrderService.getOrderByDtls(ids));
    }


    /**
     * 订单合并派车
     */
    @ApiOperation("修改订单")
    @PostMapping("/addAll")
    @Transactional(rollbackFor = Exception.class)
    public R<Void> addAll(@Validated(AddGroup.class) @RequestBody OrderVo vo) {

        OrderBo bo = new OrderBo();
        BeanUtil.copyProperties(vo, bo);
        return toAjax(iOrderService.inserAllByBo(bo) ? 1 : 0);
    }

}
